package cn.bigfire.wedesk.store;

import io.netty.util.concurrent.DefaultEventExecutorGroup;
import io.netty.util.concurrent.EventExecutorGroup;

import java.util.concurrent.Callable;
import java.util.concurrent.Future;

public class AsyncUtil {

    //异步线程池
    //异步处理线程池,不阻塞业务线程
    public static final EventExecutorGroup pool = new DefaultEventExecutorGroup(30, r -> {
        Thread thread = new Thread(r);
        thread.setName(String.format("[asyncThread-%s]", thread.getId()));
        return thread;
    });

    public static void execute(Runnable command) {
        pool.execute(command);
    }

    public static Future<?> submit(Runnable task) {
        return pool.submit(task);
    }

    public static <T> Future<T> submit(Callable<T> task) {
        return pool.submit(task);

    }

    public static <T> Future<T> submit3(Runnable task, T result) {
        return pool.submit(task, result);
    }

}
